<template>
  <el-card shadow="never" style="margin-bottom: 16px;">
    <div v-if="title !== null" slot="header">
      <span>{{ title }}</span>
    </div>

    <el-form label-width="auto" :size="size" label-position="right" :inline="inline">
      <el-form-item
          v-for="(field, index) in fields"
          :key="index"
          :label="field.name"
          label-width="80px"
      >
        <el-input v-model="data[field.field]" :placeholder="'请输入' + field.name"></el-input>
      </el-form-item>
      <el-form-item label=" " label-width="80px">
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: 'baseForm',
  props: {
    /** 字段 **/
    fields: {
      default: function () {
        return []
      },
      type: Array
    },
    /** 数据 **/
    data: {
      type: Object,
      default: function () {
        return {}
      }
    },
    /** 标题 **/
    title: {
      type: String,
      default: null
    },
    inline: {
      type: Boolean,
      default: false
    },
    /** 尺寸 **/
    size: {
      type: String,
      default: 'small'
    }
  },

  data () {
    return {}
  },

  methods: {
    submit () {
      this.$emit('submit')
    }
  }
}
</script>

<style scoped>
</style>
